#ifndef orbitshpp
#define orbitshpp

#include "common.hpp"
#include "conicPath.hpp"

class basePosition;

/* State vector class */
class stvec
{
public:
	double px;
	double py;
	double vx;
	double vy;
	int64_t t; // time at which this state was recorded - required for describing an orbit
	std::weak_ptr<basePosition> par;

	stvec();

	stvec(double inpx, double inpy);

	stvec(double inpx, double inpy, double invx, double invy);

	double pabs();

	double vabs();
};

/* Orbit vector class */
class orvec
{
public:
	double sma;      // semimajor axis
	double ecc;      // eccentricity
	double omega;    // argument of periaps from x-axis (clockwise)
	std::weak_ptr<basePosition> par;       // std gravatational parameter of parent body
	int64_t t0;      // time of a visit to the periaps
	signed char dir; // direction of travel around the orbit

	orvec();

	int64_t period();

	double n();

	unsigned char shape();
};

stvec stateFromOrbit(orvec orbit, int64_t time);

orvec orbitFromState(stvec state);

void  pathFromOrbit( conicPath * inpath, orvec orbit );

std::string toString(stvec invec);

std::string toString(orvec invec);

stvec operator+(stvec a, const stvec& b);

stvec operator-(stvec a, const stvec& b);


class bad_orbit : public std::exception
{
public:
	orvec orbit;

	bad_orbit(orvec inorbit);

	const char* what() const noexcept;
};

class bad_state : public std::exception
{
public:
	stvec state;

	bad_state(stvec state);

	const char* what() const noexcept;
};

#endif // orbitshpp
